From: Jacek Caban <jacek@codeweavers.com>
Subject: [PATCH] server: Fix setting context flags in get_thread_context.
Message-Id: <a24cb3aa-abc7-dbde-11bd-e2b7e3fbc578@codeweavers.com>
Date: Sat, 25 Apr 2020 21:13:33 +0200


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49011
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
---
  dlls/kernel32/tests/thread.c | 15 +++++++++++++++
  server/thread.c              |  2 +-
  2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c
index b6a65a4207..e068797ff5 100644
--- a/dlls/kernel32/tests/thread.c
+++ b/dlls/kernel32/tests/thread.c
@@ -1175,6 +1175,20 @@ static void test_SetThreadContext(void)
     CloseHandle( thread );
 }
 
+static void test_GetThreadContext(void)
+{
+    CONTEXT ctx;
+    BOOL ret;
+
+    memset(&ctx, 0xcc, sizeof(ctx));
+    ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
+    ret = GetThreadContext(GetCurrentThread(), &ctx);
+    ok(ret, "GetThreadContext failed: %u\n", GetLastError());
+    ok(ctx.ContextFlags == CONTEXT_DEBUG_REGISTERS, "ContextFlags = %x\n", ctx.ContextFlags);
+    ok(!ctx.Dr0, "Dr0 = %x\n", ctx.Dr0);
+    ok(!ctx.Dr1, "Dr0 = %x\n", ctx.Dr0);
+}
+
 static void test_GetThreadSelectorEntry(void)
 {
     LDT_ENTRY entry;
@@ -2379,6 +2393,7 @@ START_TEST(thread)
 #ifdef __i386__
    test_SetThreadContext();
    test_GetThreadSelectorEntry();
+   test_GetThreadContext();
    test_NtSetLdtEntries();
 #endif
    test_QueueUserWorkItem();
diff --git a/server/thread.c b/server/thread.c
index cfdf42c756..7c1c1108eb 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -1848,7 +1848,7 @@ DECL_HANDLER(get_thread_context)
             {
                 assert( reply->self );
                 memset( context, 0, sizeof(context_t) );
-                context->cpu = thread_context->regs.cpu;
+                context->cpu = thread->process->cpu;
                 if (req->flags & system_flags)
                 {
                     get_thread_context( thread, context, req->flags & system_flags );

